
<script>
import dmbForm from "@/components/DmbForm";
import dmbTable from "@/components/LTable/index.vue";
import {
  formBase,
  tableBase,
  cellStyle,
  headerCellStyle,
  tableFormStyle,
  formItemStyle,
} from "./config";
import { mapState } from "vuex";
import dayjs from "dayjs";
import store from "@/store";
const defaultForm = {
  startTime: "",
  endTime: "",
  shelfEmployee: "",
};
import { customsClearanceCompany_ListAPI } from "@/api/data/customs-clearance-company.js";

export default {
  name: "specialdel",
  computed: {
    ...mapState({
      company: (state) => state.custom_dict.company,
      carrier: (state) => state.custom_dict.carrier,
      category: (state) => state.custom_dict.category,
      warehouse: (state) => state.custom_dict.warehouse,
      shop: (state) => state.custom_dict.shop,
    }),
    formItemStyle() {
      return formItemStyle;
    },
    tableFormStyle() {
      return tableFormStyle;
    },
    cellStyle() {
      return cellStyle;
    },
    headerCellStyle() {
      return headerCellStyle;
    },
  },
  components: { dmbTable, dmbForm },
  data() {
    return {
      propsSearchForm: { ...defaultForm },
      rebase: formBase,
      requestConfig: {
        url: "/base/product/selectDeliveryListVoList",
        method: "get",
        montage: true,
      },
      dayjs,
      selectionArr: [], // 多选框内容
      selectionArr2: [], // 多选框内容
      tableSearchForm: { ...defaultForm },
      listUser: [],
      customsClearanceCompany_List: [],
    };
  },
  mounted() {
    customsClearanceCompany_ListAPI()
      .then((res) => {
        console.log(
          "清关",
          res,
          this.rebase.find((el) => el.label === "清关公司")
        );
        this.rebase.find((el) => el.label === "清关公司").options = res.rows;
        this.customsClearanceCompany_List = res.rows;
      })
      .catch((err) => {});
  },
  methods: {
    tableBase() {
      return tableBase;
    },
    // 导出
    async downLoad() {
      if (this.selectionArr.length > 0) {
        const customsClearanceNos = this.selectionArr.map(
          (v) => v.customsClearanceNo
        );
        this.download(
          "/base/product/exportDeliveryListVoList",
          {
            customsClearanceNos,
          },
          `出库清单详细_${dayjs().format("YYYY-MM-DD HH:mm:ss")}.xlsx`
        );
      } else {
        this.$message.error("请选择条数据导出");
      }
    },
    // 多选框内容
    selectionChange(data) {
      this.selectionArr = data;
    },
    CustomDoubleClick(row) {
      console.log(row, "自定义事件");
    },
  },
  watch: {
    propsSearchForm: {
      deep: true,
      handler: function (value) {
        this.tableSearchForm = { ...value };
        delete this.tableSearchForm.shelfTime;
        // 日期
        if (!value?.shelfTime?.length) {
          this.tableSearchForm.startTime = "";
          this.tableSearchForm.endTime = "";
        } else if (value?.shelfTime?.length) {
          this.tableSearchForm.startTime = dayjs(value.shelfTime[0]).format(
            "YYYY-MM-DD HH:mm:ss"
          );
          this.tableSearchForm.endTime = dayjs(value.shelfTime[1]).format(
            "YYYY-MM-DD HH:mm:ss"
          );
        }
        //承运商
        if (value.carrier) {
          const obj = this.carrier.find((item) => {
            return item.id == value.carrier;
          });
          this.tableSearchForm.carrier = obj ? obj.carrierName : "";
        }
        // 货物类别
        if (value.cargoCategory) {
          const obj = this.category.find((item) => {
            return item.id == value.cargoCategory;
          });
          this.tableSearchForm.cargoCategory = obj ? obj.cargoName : "";
        }
        // 清关公司
        if (value.customsClearanceCompany) {
          const obj = this.customsClearanceCompany_List.find((item) => {
            return item.id == value.customsClearanceCompany;
          });
          this.tableSearchForm.customsClearanceCompany = obj
            ? obj.customsName
            : "";
        }
        // 仓库
        if (value.warehouse) {
          const obj = this.warehouse.find((item) => {
            return item.id == value.warehouse;
          });
          this.tableSearchForm.warehouse = obj ? obj.warehouseName : "";
        }
        // 店铺
        if (value.storeName) {
          const obj = this.shop.find((item) => {
            return item.id == value.storeName;
          });
          this.tableSearchForm.storeName = obj ? obj.shopName : "";
        }
      },
    },
  },
};
</script>

<template>
  <div>
    <div class="overflow-auto">
      <dmb-form
        ref="form"
        :form-items="rebase"
        :model-value="propsSearchForm"
        :item-style="formItemStyle"
    @update="(row) => (propsSearchForm = row)"
      >
        <template v-slot:header="row" class="flex flex-row-reverse">
          <div class="mb-3 flex flex-row-reverse">
            <div>
              <el-button type="success" @click="$refs.table.getListData()"
                >查询</el-button
              >
              <el-button type="primary" @click="downLoad">导出</el-button>
            </div>
          </div>
        </template>
      </dmb-form>
    </div>
    <dmb-table
      ref="table"
      :CustomDoubleClick="true"
      @CustomDoubleClick="CustomDoubleClick"
      :prop-list="tableBase()"
      :show-index-column="true"
      select-column-type="CHECKBOX"
      :props-search-form="tableSearchForm"
      :req-request="requestConfig"
      select-key="customsClearanceNo"
      :cell-style="cellStyle"
      :header-cell-style="headerCellStyle"
      :initialize="false"
      :change-search-form="false"
      :show-footer="true"
      :form-item-style="tableFormStyle"
      @selectionChange="
        (row) => {
          selectionArr = row;
        }
      "
    >
      <template v-slot:isTaxed="{ row }">
        <el-checkbox
          disabled
          true-label="1"
          false-label="0"
          v-model="row.isTaxed"
        ></el-checkbox>
      </template>
      <template v-slot:baggingTime="{ row }">
        {{
          row.baggingTime
            ? dayjs(row.baggingTime).format("YYYY-MM-DD HH:mm:ss")
            : "--"
        }}
      </template>
      <template v-slot:orderTime="{ row }">
        {{
          row.orderTime
            ? dayjs(row.orderTime).format("YYYY-MM-DD HH:mm:ss")
            : "--"
        }}
      </template>
      <template v-slot:printingTime="{ row }">
        {{
          row.printingTime
            ? dayjs(row.printingTime).format("YYYY-MM-DD HH:mm:ss")
            : "--"
        }}
      </template>
      <template v-slot:loadingTime="{ row }">
        {{
          row.loadingTime
            ? dayjs(row.loadingTime).format("YYYY-MM-DD HH:mm:ss")
            : "--"
        }}
      </template>
    </dmb-table>
  </div>
</template>

<style scoped lang="scss">
::v-deep .el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
  background-color: #1890ff !important;
  border-color: #dcdfe6;
  cursor: default !important;
}
</style>
